﻿using Castle.Core;
using Castle.DynamicProxy;
using System.Reflection;

namespace ManYan.Common.Intercept
{
    public class FilterIntercept : IInterceptor
    {
        public void Intercept(IInvocation invocation)
        {
            Console.WriteLine("进入拦截器");
            MethodInfo method = invocation.GetConcreteMethod();
            foreach (var item in invocation.Arguments)
            {
                Console.WriteLine(item);
            }
            if (!invocation.MethodInvocationTarget.IsAbstract)
            {
                try
                {

                    invocation.Proceed();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine("" + invocation.ReturnValue);
            }
           Console.WriteLine("被拦截的方法执行完毕");
           
        }
    }
}
